package com.wrupple.muba.catalogs.client.module.services.logic.impl;

import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.json.client.JSONObject;
import com.wrupple.muba.catalogs.client.module.services.CatalogVegetateSerializer;
import com.wrupple.vegetate.domain.CatalogObject;
import com.wrupple.vegetate.domain.CatalogResponseContract;

public class CatalogVegetateSerializerImpl implements CatalogVegetateSerializer {

	@Override
	public CatalogResponseContract deserialize(String string) {
		return parseResponse(string);
	}

	@Override
	public String serialize(CatalogObject object) {
		if (object == null) {
			return null;
		}
		return new JSONObject((JavaScriptObject) object).toString();
	}

	protected final native JsCatalogResponseContract parseResponse(
			String response) /*-{
								return eval("[" + response + "]")[0];
								}-*/;

}
